# -*- coding: utf-8 -*-
'''
Created on 2012-8-23

@author: null
'''
from models import User
from dao import BaseDataAccess

class UserDataAccess(BaseDataAccess):

    def add_user(self, user):
        self.db.add(user);
        self.db.commit();
        return user.id;
    
    def is_email_registered(self, email):
        if not email:
            raise Exception("email cannot be empty.");
        email = email.lower();
        count = self.db.query(User).filter(User.email == email).count();
        return count > 0;
    
    def get_user(self, email):
        result = self.db.query(User).filter(User.email == email).first();
        return result;